Skip to content

Initial setup: Add AWS CDK constructs library with comprehensive features#1

Merged
ncipollina merged 6 commits into
mainfrom
feature/initial-setup
Jul 3, 2025
Merged

Initial setup: Add AWS CDK constructs library with comprehensive features#1
ncipollina merged 6 commits into
mainfrom
feature/initial-setup

Conversation

@ncipollina

Copy link
Copy Markdown
Contributor

Summary

  • Created complete AWS CDK constructs library for .NET with LambdaFunctionConstruct
  • Implemented OpenTelemetry integration and IAM management
  • Fixed CS0618 warning by replacing deprecated LogRetention with explicit LogGroup
  • Added comprehensive test suite with xUnit v3 and AutoFixture
  • Created detailed README with installation guides, usage examples, and documentation

Key Features

  • LambdaFunctionConstruct: Complete Lambda setup with IAM roles, policies, and logging
  • OpenTelemetry Integration: AWS OTEL Collector layer with X-Ray tracing
  • Versioning Support: Automatic version creation with "live" alias
  • Multi-target Permissions: Applies permissions to function, version, and alias
  • Comprehensive Testing: 11 unit tests with realistic test data using AutoFixture

Test plan

  • Build solution successfully (dotnet build)
  • All 11 tests pass (dotnet run --project test/LayeredCraft.Cdk.Constructs.Tests/ --framework net8.0)
  • No compiler warnings or errors
  • README documentation is complete and accurate
  • NuGet package configuration is properly set up

🤖 Generated with Claude Code

- Add LambdaFunctionConstruct with IAM roles, policies, and logging
- Implement OpenTelemetry integration with AWS OTEL Collector layer
- Add versioning and alias support for Lambda deployments
- Fix CS0618 warning by replacing deprecated LogRetention with LogGroup
- Create comprehensive test suite with xUnit v3 and AutoFixture
- Add detailed README with installation, usage examples, and documentation
- Update project configuration for NuGet packaging

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ncipollina
ncipollina requested a review from Copilot July 3, 2025 13:11

This comment was marked as outdated.

Renamed includeOtelLayer1 and includePermissions1 to match the
constructor parameter names for better code clarity and readability.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ncipollina
ncipollina requested a review from Copilot July 3, 2025 13:16

This comment was marked as outdated.

@ncipollina
ncipollina requested a review from Copilot July 3, 2025 13:19

This comment was marked as outdated.

@ncipollina
ncipollina requested a review from Copilot July 3, 2025 13:21

This comment was marked as outdated.

ncipollina and others added 3 commits July 3, 2025 09:24
…ation

- Add assertions to verify logs:CreateLogStream, logs:CreateLogGroup, logs:TagResource actions
- Add assertion to verify logs:PutLogEvents action in separate policy statement
- Verify correct ARN resources for both log group and log stream levels
- Test now properly validates the CloudWatch Logs permissions as intended

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…sabled test

- Verify TracingConfig property is not present when OTEL layer is disabled
- Verify Layers property is not present when OTEL layer is disabled
- Use Match.Not() with Match.AnyValue() to assert properties are absent
- Test now properly validates the disabled tracing behavior as intended

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Use discard pattern (_) for unused construct variables
- Simplify permission count logic with early return
- Remove unnecessary variable assignments for cleaner code

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ncipollina
ncipollina requested a review from Copilot July 3, 2025 13:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR bootstraps a new .NET AWS CDK constructs library with end-to-end Lambda function support and adds a full test suite.

  • Introduces LambdaFunctionConstruct with IAM, logging, versioning, and optional OpenTelemetry integration
  • Defines configuration models (LambdaFunctionConstructProps, LambdaPermission) and test utilities with AutoFixture
  • Adds comprehensive xUnit v3 tests, project/solution configuration, CI workflows, and detailed README

Reviewed Changes

Copilot reviewed 17 out of 20 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/LayeredCraft.Cdk.Constructs.Tests/xunit.runner.json Add xUnit runner schema config
test/LayeredCraft.Cdk.Constructs.Tests/TestKit/Customizations/LambdaFunctionConstructCustomization.cs Define AutoFixture customization for Lambda props
test/LayeredCraft.Cdk.Constructs.Tests/TestKit/Attributes/LambdaFunctionConstructAutoDataAttribute.cs Create custom AutoData attribute for parameterized tests
test/LayeredCraft.Cdk.Constructs.Tests/TestKit/Attributes/BaseFixtureFactory.cs Provide base AutoFixture setup with recursion and NSubstitute
test/LayeredCraft.Cdk.Constructs.Tests/LayeredCraft.Cdk.Constructs.Tests.csproj Configure test project references and global usings
test/LayeredCraft.Cdk.Constructs.Tests/Constructs/LambdaFunctionConstructTests.cs Add unit tests covering all construct behaviors
src/LayeredCraft.Cdk.Constructs/Models/LambdaPermission.cs Define model for Lambda invocation permissions
src/LayeredCraft.Cdk.Constructs/Models/LambdaFunctionConstructProps.cs Define props interface and record for Lambda construct
src/LayeredCraft.Cdk.Constructs/LayeredCraft.Cdk.Constructs.csproj Configure library project metadata and dependencies
src/LayeredCraft.Cdk.Constructs/Constructs/LambdaFunctionConstruct.cs Implement core Lambda CDK construct (IAM, logs, OTEL, versioning)
README.md Add installation, usage examples, API reference, and project structure
LayeredCraft.Cdk.Constructs.sln Initialize solution including src and test projects
Directory.Build.props Define package defaults, metadata, and source linking
CLAUDE.md Add guidance for Claude Code generation
.github/workflows/pr-build.yaml Add PR validation workflow
.github/workflows/build.yaml Add main build and packaging workflow
.github/dependabot.yml Configure Dependabot for NuGet updates
Comments suppressed due to low confidence (3)

test/LayeredCraft.Cdk.Constructs.Tests/TestKit/Attributes/BaseFixtureFactory.cs:1

  • The BaseFixtureFactory references types like Fixture, IFixture, ThrowingRecursionBehavior, and OmitOnRecursionBehavior from AutoFixture but does not include 'using AutoFixture;'. Add the missing using directive to avoid compile errors.
using AutoFixture.AutoNSubstitute;

src/LayeredCraft.Cdk.Constructs/Models/LambdaFunctionConstructProps.cs:27

  • Initializing a List with '[]' will not compile. Replace with a proper List initializer, e.g., 'new List()'.
    public List<LambdaPermission> Permissions { get; set; } = [];

test/LayeredCraft.Cdk.Constructs.Tests/TestKit/Customizations/LambdaFunctionConstructCustomization.cs:36

  • You’re assigning an array via '[]' to a List property, causing a type mismatch. Use 'new List { fixture.Create() }' or another List initializer.
            .With(props => props.Permissions, includePermissions 

@ncipollina
ncipollina merged commit 88850bc into main Jul 3, 2025
1 check passed
@ncipollina
ncipollina deleted the feature/initial-setup branch July 3, 2025 13:35
ncipollina added a commit that referenced this pull request Jul 8, 2025
- Replace array initializations with modern C# collection expressions ([])
- Use discard operator (_) for unused construct variables in tests
- Move DynamoDB constructs from Constructs/ to root folder
- Fix 8 failing unit tests related to DynamoDB template assertions
- Add comprehensive DynamoDB construct testing support
- Update CloudFormation output assertions to use export names instead of logical IDs
- Implement proper AttributeType mapping for DynamoDB assertions

Fixes #1

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
ncipollina added a commit that referenced this pull request Jul 8, 2025
)

* Update codebase to use collection expressions and fix failing tests

- Replace array initializations with modern C# collection expressions ([])
- Use discard operator (_) for unused construct variables in tests
- Move DynamoDB constructs from Constructs/ to root folder
- Fix 8 failing unit tests related to DynamoDB template assertions
- Add comprehensive DynamoDB construct testing support
- Update CloudFormation output assertions to use export names instead of logical IDs
- Implement proper AttributeType mapping for DynamoDB assertions

Fixes #1

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix README documentation to use correct API types and collection expressions

- Replace AttributeDefinition with Attribute in DynamoDB examples
- Update array initializations to use collection expressions
- Ensure documentation matches actual construct API

Addresses GitHub Copilot feedback on API consistency

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Add default partition key to CreateDynamoDbTablePropsBuilder and comprehensive unit tests

- Set default partition key "pk" with STRING type in CreateDynamoDbTablePropsBuilder since it's required for DynamoDB table creation
- Add comprehensive unit tests to verify default partition key is set correctly
- Add tests to verify customization capabilities and valid table creation
- Update documentation to explain the default partition key requirement

Addresses GitHub Copilot feedback about missing required partition key

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Add comprehensive test coverage for DynamoDB testing helpers to achieve 100% coverage

This commit adds 46 comprehensive unit tests covering both DynamoDB testing helper classes:

**DynamoDbTableConstructAssertions (100% coverage):**
- ShouldHaveDynamoTable with various scenarios
- ShouldHavePartitionKey with all AttributeTypes (STRING, NUMBER, BINARY)
- ShouldHaveSortKey with all AttributeTypes (STRING, NUMBER, BINARY)
- ShouldHaveGlobalSecondaryIndex with GSI validation
- ShouldHaveTableStream with all StreamViewTypes (NEW_IMAGE, OLD_IMAGE, NEW_AND_OLD_IMAGES, KEYS_ONLY)
- ShouldHaveTimeToLiveAttribute with TTL validation
- ShouldHaveTableOutputs with case normalization and comprehensive error scenarios
- ShouldHaveGlobalSecondaryIndexCount with zero, single, and multiple GSI scenarios

**DynamoDbTableConstructPropsBuilder (100% coverage):**
- Constructor defaults validation
- All With* methods (table name, partition key, sort key, removal policy, billing mode)
- GSI configuration with both partition-only and partition+sort key scenarios
- Stream configuration with WithStream and WithoutStream
- TTL configuration with WithTimeToLiveAttribute and WithoutTimeToLiveAttribute
- Scenario-based configurations: ForUserTable, ForSessionTable, ForEventSourcing
- Method chaining and value overwriting behavior
- Full integration test creating actual DynamoDB construct

**Coverage highlights:**
- Tests all code paths including error conditions
- Validates all AttributeTypes and StreamViewTypes
- Tests case normalization and export name validation
- Comprehensive error message validation
- Integration tests with actual CDK constructs
- Tests both positive and negative scenarios

Total test count increased from 95 to 141 tests (46 new tests added)
All tests pass with 100% coverage on both DynamoDB testing helper classes

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Simplify CreateDynamoDbTablePropsBuilder by removing redundant default calls

Address GitHub Copilot feedback to reduce redundancy in CreateDynamoDbTablePropsBuilder:

- Remove explicit WithTableName("test-table") - builder already defaults to "test-table"
- Remove explicit WithBillingMode(PAY_PER_REQUEST) - builder already defaults to PAY_PER_REQUEST
- Remove explicit WithRemovalPolicy(DESTROY) - builder already defaults to DESTROY
- Keep only WithPartitionKey("pk") since partition key defaults to null but is required for DynamoDB

This change:
- Reduces redundancy by relying on builder's built-in defaults
- Focuses only on the essential override (partition key)
- Maintains same functionality with cleaner, more maintainable code
- Updates documentation to clarify the builder's built-in defaults

All 141 tests continue to pass, confirming no functional changes.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants